package org.evolver.disser;

import javax.swing.*;

import org.apfloat.Apfloat;

public class IntegerParameter {
    class IntegerVerifier extends InputVerifier {
        public boolean verify(JComponent input) {
            boolean pass = true;

            JTextField tf = (JTextField) input;
            try {
                Integer.valueOf(tf.getText());
            } catch (NumberFormatException e) {
                // If valueOf() above threw NumberFormatException
                // there is user error in the input data
                pass = false;
            }
            
            return pass;
        }
    }
    private String     myLabel;
    private String     myUnit;
    private Integer    myValue;
    private JTextField myField;

    public IntegerParameter(String label, String unit, Integer defaultValue) {
        myLabel = label;
        myUnit = unit;
        myValue = new Integer(defaultValue);
    }

    public void addToPanel(JPanel p) {
        p.add(new JLabel(myLabel), "gap 10");
        myField = new JTextField(myValue.toString());
        myField.setInputVerifier(new IntegerVerifier());
        p.add(myField, "w 75!");
        p.add(new JLabel(myUnit), "wrap");
    }

    public Integer getValue() {
        myValue = new Integer(Integer.valueOf(myField.getText()));
        return myValue;
    }
}
